﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace gixoom.Dom.Block
{
    /// <summary>
    /// Represents a container for block id and content.
    /// It is not necessary for id to correspond to content.
    /// </summary>
    internal class Block: IBlock
    {
        private IBlockId id;
        private byte[] content;
        private ReadOnlyCollection<byte> contentReadOnly;

        public Block(IBlockId id, byte[] content)
        {
            Ensure.ArgumentNotNull(id, "id");
            Ensure.ArgumentNotNull(content, "content");

            this.id = id;
            this.content = content;
            contentReadOnly = Array.AsReadOnly(content);
        }

        public IBlockId Id
        {
            get
            {
                return id;
            }
        }

        public ReadOnlyCollection<byte> GetContent()
        {
            return contentReadOnly;
        }

        public byte[] GetContentCopy()
        {
            byte[] contentCopy = new byte[content.Length];
            content.CopyTo(contentCopy, 0);

            return contentCopy;
        }
    }
}
